<?php
include('class/class_connect.php');
include('class/class_page.php');
include('class/class_comments.php');
include('class/class_news.php');
include('class/class_acts.php');
include('class/class_address.php');
include('class/class_workdays.php');
include('class/class_rating.php');
include('class/tabs/class_tabs.php');
include('class/abstract/class_mainObjectInfo.php');
include('class/city_rus.php');
include('class/class_checkGetData.php');

$aCheck=new checkGetData('m');
foreach($_GET as $key=>$vol)
	$_GET[$key]=$aCheck->safetyCheck($vol);
foreach($_POST as $key=>$vol)
	$_POST[$key]=$aCheck->safetyCheck($vol);
$aCheck->checkTableId($_GET['city'], $_GET['id']);

$aComment=new comments('m', $_GET['city'], $_GET['id']);
$aComment->addComment();
session_start();
if($_SESSION['login']=='zhendos')$admin=true;
if(isset($_POST['editStatus']) && $admin)
{
	$aConnect=new connect('m');
	$aConnect->update_data($_GET['city'], "status='".$_POST['status']."'", "WHERE id='".$_GET['id']."'");
}

class aFirmPage extends page
{
	var $row=array();
	var $cityRus;
	function __construct()
	{
		$aConnect=new connect('m');
		$this->row=mysql_fetch_array($aConnect->select_all($_GET['city'], "WHERE id='".$_GET['id']."'"));
		$this->cityRus=new city_rus_class();
		parent::__construct();
	}
	function title()
	{
		echo $this->row['name'].' '.$this->cityRus->city_rus_im($_GET['city']);
	}
	function maincontent()
	{
		if($_SESSION['login']=='zhendos')
		{
			echo ('
			<link rel="stylesheet" type="text/css" href="style/admin.css" />
			<div class="adminPanel">
				<a href="adminEditMalls.php?city='.$_GET['city'].'&id='.$this->row['id'].'">Редактировать</a><br />
				<a href="#" onclick="document.getElementById(\'editStatus\').style.display=\'block\';">Изменить статус</a>
				<div id="editStatus" style="display: none">
				<form name="firmsStatus" action="" method="post">
					Новая<input name="status" type="radio" value="0"
					');
					if($this->row['status']=='0')echo 'checked';
					echo ('
					><br />
					Активная<input name="status" type="radio" value="1"
					');
					if($this->row['status']=='1')echo 'checked';
					echo ('
					><br />
					Заблокировать<input name="status" type="radio" value="2"
					');
					if($this->row['status']=='2')echo 'checked';
					echo ('
					><br />
					<input type="submit" name="editStatus" value="Принять">
				</form>
				</div>
			</div>
			');
		}
		echo ('
		<link rel="stylesheet" type="text/css" href="style/malls.css" />
		<div class="photoFrame">
		</div>
		<script type="text/javascript" src="scripts/mallsSearchSuggest.js">
		</script>
		<div class="route">
			<div class="routeEl">
				<a href="malls_list.php?city='.$_GET['city'].'">Торговые центры</a>
			</div>
			<div class="routeEl">
				'.$this->row['name'].'
			</div>
		</div>
		');
		$aFirmInfo=new aFirmInfo($this->row);
		echo '<br />';
    	$aTab=new aFirmTabs();
	}
	function metaData()
	{
		$robots='INDEX,FOLLOW';
		$description=$this->row['short'].' '.$this->row['name'].' в городе '.$this->cityRus->city_rus_im($_GET['city']).'.
		Адрес, телефон, сайт, часы работы, фирмы, отзывы, фотографии, события и другая информация о компании '.$this->row['short'].' '.$this->row['name'];
		$keywords=$this->row['name'].','.$this->row['short'].','.$this->cityRus->city_rus_im($_GET['city']).','.
		str_replace(' ',',',$this->row['subdiv']).',торговые центры';
		return array('name'=>array('Robots'=>$robots,
 								   'Description'=>$description,
 								   'Keywords'=>$keywords,
 								   ),
 					);
	}
}

class aFirmTabs extends tabs
{
	function __construct()
	{
		$labels=array('Фирмы', 'Отзывы', 'O нас', 'Новости', 'События');
		parent::__construct($labels);
	}
	function content0()
	{
		$aConnect=new connect('m');
		$row=mysql_fetch_array($aConnect->select_all($_GET['city'], "WHERE id='".$_GET['id']."'"));
		if(!$row['firms'])return;
		$mallsFirmsArray=explode('|', $row['firms']);
		for($i=0; $i<count($mallsFirmsArray); $i++)
		{
			$aMallsFirm=$mallsFirmsArray[$i];
			$aMallsFirmEl=explode('^', $aMallsFirm);
			$aMallsFirmId=$aMallsFirmEl[0];
			$aMallsFirmName=$aMallsFirmEl[1];
			$aMallsFirmSubdiv=$aMallsFirmEl[2];
			$aFirm[$aMallsFirmSubdiv][]=$aMallsFirmId.','.$aMallsFirmName;

		}
		//print_r($aFirm);
		arsort($aFirm);
		//print_r($aFirm);
		//$subdivSort=0;
		echo ('
		<input id="mallsId" name="mallsId" type="hidden" value="'.$_GET['id'].'">
		<center>
		<div id="mallsSearch">
			<form name="" id="mallsSearchForm" action="mallsFirms.php?city='.$_GET['city'].'&id='.$_GET['id'].'" method="post">
	        	<input id="mallsSearchInput" name="mallsSearch" type="text" value="" autocomplete="off">
	        	<input type="submit" value="Поиск" name="mallsSearchButton" class="searchButton">
			</form>
			<div id="mallsSearchSuggest">
			</div>
		</div>
		</center>
		');
		$n=0;
		foreach($aFirm as $aFirm=>$subdiv)
		{
			if($n==7)break;
			$n++;
			echo ('
			<div class="mallsSubdiv" align="center">
				<a href="mallsFirms.php?city='.$_GET['city'].'&id='.$_GET['id'].'&mallsSearch='.$aFirm.'">'.$aFirm.' ('.count($subdiv).')</a>
			</div>
			<div class="mallsFirmsList">
			');
			for($i=0; $i<8; $i++)
			{
				$aFirmsId=$subdiv[$i];
				$firmsIdNameArray=explode(',', $subdiv[$i]);
				$aFirmsId=$firmsIdNameArray[0];
				$aFirmsName=$firmsIdNameArray[1];
				echo ('

					<a href="firms.php?city='.$_GET['city'].'&id='.$aFirmsId.'">
						<div class="mallsFirms">
				');
				if(file_exists('pictures/firmspics/'.$_GET['city'].'/'.$aFirmsId.'.jpg'))
				{
					echo ('
							<img class="mallsPics" src="pictures/firmspics/'.$_GET['city'].'/'.$aFirmsId.'.jpg" title="'.$aFirmsName.'" />
					');
				}
				echo ('
						</div>
					</a>

				');
				//echo $aFirmsId.$aFirmsName;
			}
			echo ('
			</div>
			');
			//echo count($subdiv);
			//echo $subdiv;
			//echo $aFirm;

		}
        echo '<center><a id="allFirmsLink" href="mallsFirms.php?city='.$_GET['city'].'&id='.$_GET['id'].'">Все фирмы</a></center>';
	}
	function content1()
	{
		$aComment=new comments('m', $_GET['city'], $_GET['id']);
		$comConnect=new connect('mc');
		$comNum=mysql_num_rows(connect::select_all($_GET['city'], "WHERE m_id='".$_GET['id']."'"));
		if($comNum==0)$comsName="Будьте первым";
		else if($comNum<=3)$comsName="Все отзывы";
		else $comsName="Последние отзывы";
		echo ('<div class="tabHeader"><h3>'.$comsName.'</h3></div>');
		$aComment->showComments(3);
		$aComment->commentForm($_SESSION['login']);
	}
	function content3()
	{
		$aNews=new news('malls', $_GET['city'], $_GET['id']);
		$newsConnect=new connect('mn');
		$newsesNum=mysql_num_rows(connect::select_all($_GET['city'], "WHERE malls_id='".$_GET['id']."'"));
		if($newsesNum==0)$newsesName="Новостей нет";
		else if($newsesNum<=3)$newsesName="Все новости";
		else $newsesName="Последние новости";
		echo ('<div class="tabHeader"><h3>'.$newsesName.'</h3></div>');
		$aNews->showNews('fullnews.php?city='.$_GET['city'].'&obj=malls&id='.$_GET['id'].'&news_id=', 3, 200);
	}
	function content2()
	{
  		$aConnect=new connect('m');
		$row=mysql_fetch_array($aConnect->select_all($_GET['city'], "WHERE id='".$_GET['id']."'"));
		$text=nl2br($row['stext']);
		echo ('
		<script type="text/javascript" src="scripts/showPhoto.js">
		</script>
		<link rel="stylesheet" type="text/css" href="style/aboutFirms.css" />

		<div class="firmsPhotos" align="center">
			<table class="photoTable" border="0">
				<tr>
			');
			if(file_exists('pictures/mallsphoto/'.$_GET['city'].'/'.$_GET['id'].''))
			{
				for($i=1; $i<=5; $i++)
				{
					if(file_exists('pictures/mallsphoto/'.$_GET['city'].'/'.$_GET['id'].'/'.$i.'.jpg'))
					{
						echo ('
						<td class="aPhotoTr" align="center">
							<img class="firmsPhoto" id="firmsPhoto'.$i.'" src="pictures/mallsphoto/'.$_GET['city'].'/'.$_GET['id'].'/'.$i.'.jpg" height="100">
						</td>
						');
					}
				}
			}
			echo ('
				</tr>
			</table>
		</div>
		<div class="tabHeader">
			<h3>'.$row['text_title'].'</h3>
		</div>
		<div class="firmText">
			'.$text.'
		</div>
		<div class="firmsPhotos" align="center">
			<table class="photoTable" border="0">
				<tr>
			');
			if(file_exists('pictures/mallsphoto/'.$_GET['city'].'/'.$_GET['id'].''))
			{
				for($i=6; $i<=10; $i++)
				{
					if(file_exists('pictures/mallsphoto/'.$_GET['city'].'/'.$_GET['id'].'/'.$i.'.jpg'))
					{
						echo ('
						<td class="aPhotoTr" align="center">
							<img class="firmsPhoto" id="firmsPhoto'.$i.'" src="pictures/mallsphoto/'.$_GET['city'].'/'.$_GET['id'].'/'.$i.'.jpg" height="100">
						</td>
						');
					}
				}
			}
			echo ('
				</tr>
			</table>
		</div>
		');
	}
	function content4()
	{
		$act=new acts();
		$act->showActs('malls', 4, 200, $_GET['id'], false, "950px");
	}
	function mallsFirms($city, $firmsId, $firmsName, $firmsShort)
	{
		echo ('
		<a href="">
		<div class="mallsFirms">
			<div class="mallsFirmsPic">
				<img src="pictures/firmspics/'.$city.'/'.$firmsId.'.jpg" title="'.$firmsName.'">
			</div>
		</div>
		</a>
		');
	}

}

class aFirmInfo extends mainObjectInfo
{
	var $row;
	function __construct($row=array())
	{
		$this->row=$row;
		parent::__construct();
	}
	function showPic()
	{
		echo ('
		<img src="pictures/mallspics/'.$_GET['city'].'/'.$this->row['id'].'.jpg" title="'.$this->name.'">
		');
		$aFirmRating=new rating('m');
		$aFirmRating->rating($_GET['city'], $this->row['id']);
	}
	function showAddress()
	{
		$aWorkdays=new workdays();
		$address=new address();
		$explodedAddress=$this->row['address'].'^^'.$this->row['phone'].'^^'.$this->row['workdays'];
		$address->showAddress($explodedAddress, $this->row['link']);
	}
	function showshort()
	{
		echo $this->row['short'];
	}
	function showName()
	{
		echo $this->row['name'];
	}
}

$aPage=new aFirmPage($row);

?>